<template>
  <div>
      <h1>展示图书{{cid}}</h1>
      <table>
          <tr>
              <td>编号</td>
              <td>书名</td>
              <td>封面</td>
              <td>分类</td>
              <td>简介</td>
              <td>价格</td>
              <td>操作</td>
          </tr>
          <tr v-for="i in showbooks" :key="i.id">
              <td>{{i.id}}</td>
              <td>{{i.name}}</td>
              <td>{{i.cate}}</td>
              <td><img :src="'http://127.0.0.1:8000/'+i.img"></td>
              <td>{{i.intro}}</td>
              <td>i.price</td>
              <td>
                  <router-link :to="{path:'/upbooks01',query:{'bid':i.id}}"><button>修改</button></router-link>
                  <button @click="delbooks(i.id)">删除</button>
              </td>
          </tr>
      </table>

  </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            cid:this.$route.query.cid,
            showbooks:[],
        }
    },
    methods:{
        delbooks(i){
            axios({
                url:'http://127.0.0.1:8000/app01/delbooks/'+i,
                method:'delete'
            }).then(resp=>{
                console.log(resp.data)
                if(resp.data.code==200){
                    this.$router.go(0)
                }
            })
        }
    },
    created() {
        axios({
            url:'http://127.0.0.1:8000/app01/showbooks/'+this.cid,
            method:'get'
        }).then(resp=>{
            console.log(resp.data)
            this.showbooks=resp.data
        })
    }
}
</script>

<style>

</style>